cmake_minimum_required(VERSION 3.8)
project(usb_camera_sub)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# 查找必要的依赖包
find_package(GDAL REQUIRED)
find_package(CURL REQUIRED)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(OpenCV REQUIRED)

set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# 链接retinaface库
set(RETINAFACE_LIB_PATH "/mnt/sdcard/retinaface_lib/build/libretinaface_lib.so")
set(RETINAFACE_INCLUDE_PATH "/mnt/sdcard/retinaface_lib/include")

# 链接facenet库
set(FACENET_LIB_PATH "/mnt/sdcard/facenet_lib/build/libfacenet_lib.so")
set(FACENET_INCLUDE_PATH "/mnt/sdcard/facenet_lib/include")

# 用来搜索头文件的目录
include_directories(
    ${OpenCV_INCLUDE_DIRS}
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${RETINAFACE_INCLUDE_PATH}
    ${FACENET_INCLUDE_PATH}
)

# 添加可执行文件
add_executable(usb_camera_subscriber src/usb_camera_subscriber.cpp)

# 链接依赖库
target_link_libraries(usb_camera_subscriber
  ${GDAL_LIBRARIES}
  ${CURL_LIBRARIES}
  ${OpenCV_LIBS}
  ${cv_bridge_LIBRARIES}
  ${RETINAFACE_LIB_PATH}
  ${FACENET_LIB_PATH}
)

ament_target_dependencies(usb_camera_subscriber
  rclcpp
  sensor_msgs
  cv_bridge
  OpenCV
)

# 安装可执行文件
install(TARGETS
  usb_camera_subscriber
  DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
